﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using OilRigSumoWrestlers.Controllables.Controllers;
using OilRigSumoWrestlers.Entities.MenuItems;
using OilRigSumoWrestlers.Entities.MenuItems.NetworkItems;
using OilRigSumoWrestlers.Scenes.Menu;
using RaptorEngine;
using RaptorEngine.Components.Drawable;
using RaptorEngine.Managers;

namespace OilRigSumoWrestlers.Scenes.Network
{
    class SetupGame : MenuScene
    {
        public SetupGame(bool network) : base(network)
        {
            CreateHUD();
            CreateController();
        }

        private void CreateHUD()
        {
            Vector2 worldCenter = new Vector2(
                 GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.X + GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Width / 2,
                 GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Y + GameEngine.Instance.Render.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);

            string mpHostText = "Host Game";
            DrawableText optMpHostSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 40)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), mpHostText, Color.White, 1, true);
            DrawableText optMpHost = new DrawableText(new Entity(worldCenter + new Vector2(0, 40)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), mpHostText, Color.Gray, 1, true);

            string mpJoinText = "Join Game";
            DrawableText optMpJoinSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 80)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), mpJoinText, Color.White, 1, true);
            DrawableText optMpJoin = new DrawableText(new Entity(worldCenter + new Vector2(0, 80)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), mpJoinText, Color.Gray, 1, true);

            string backText = "Back";
            DrawableText optBackSelected = new DrawableText(new Entity(worldCenter + new Vector2(0, 120)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), backText, Color.White, 1, true);
            DrawableText optBack = new DrawableText(new Entity(worldCenter + new Vector2(0, 120)),
                GameEngine.Instance.Load<SpriteFont>(@"Fonts/MenuOptions"), backText, Color.Gray, 1, true);

            _menuItems.Add(new MultiplayerHostItem(optMpHostSelected, optMpHost));
            _menuItems.Add(new MultiplayerJoinItem(optMpJoinSelected, optMpJoin));
            _menuItems.Add(new ContinueGameItem(optBackSelected, optBack));
            _menuItems[_selectedItem].Select();

            foreach (MenuItem item in _menuItems)
            {
                AddEntity(item);
            }
        }

        private void CreateController()
        {
            Entity menuController = new Entity();
            menuController.AddComponent(new MenuControllable(menuController, this, RaptorEngine.Managers.LogicalPlayerIndex.One));
            AddEntity(menuController);
        }

        public override void GoBack()
        {
            if(GameEngine.Instance.Network.State != NetworkManager.NetworkState.Offline)
                GameEngine.Instance.Network.State = NetworkManager.NetworkState.Ending;
            GameEngine.Instance.Scene.RemoveCurrentScene();
            GameEngine.Instance.Scene.StartCurrentScene();
            GameEngine.Instance.Scene.ShowCurrentScene();
        }

        public override void Update()
        {
            
        }
    }
}
